﻿
<template>
<div class="card-fill layout-padding">
<el-card shadow="hover" class="layout-padding-auto" >
  <div>
    <el-form ref="formRefAndonStation" :model="stateAndonStation.vmModel" label-width="100px">
      <el-row>
        <el-col :xs="24" :lg="12" class="mb20">
        <el-form-item ref="Entity_Name_FormItem" prop="Entity.Name" :label="$t('message.autotrans._Model_AndonStation_Name')"            :rules="[{required: true, message: $t('message._system.common.vm.input',{input:$t('message.autotrans._Model_AndonStation_Name')}), trigger: 'blur' }]" >
            <el-input v-model="stateAndonStation.vmModel.Entity.Name" clearable></el-input>
        </el-form-item>

        </el-col>
        <el-col :xs="24" :lg="12" class="mb20">
        <el-form-item ref="Entity_Code_FormItem" prop="Entity.Code" :label="$t('message.autotrans._Model_AndonStation_Code')"            :rules="[{required: true, message: $t('message._system.common.vm.input',{input:$t('message.autotrans._Model_AndonStation_Code')}), trigger: 'blur' }]" >
            <el-input v-model="stateAndonStation.vmModel.Entity.Code" clearable></el-input>
        </el-form-item>

        </el-col>
        <el-col :xs="24" :lg="12" class="mb20">
        <el-form-item ref="Entity_DeviceUserId_FormItem" prop="Entity.DeviceUserId" :label="$t('message.autotrans._Model_AndonStation_DeviceUser')"            :rules="[{required: true, message: $t('message._system.common.vm.input',{input:$t('message.autotrans._Model_AndonStation_DeviceUser')}), trigger: 'blur' }]" >
            <el-select v-model="stateAndonStation.vmModel.Entity.DeviceUserId" clearable>
               <el-option v-for="item in stateAndonStation.AllDeviceUsers" :key="item.Value" :value="item.Value" :label="item.Text"></el-option>
            </el-select>
        </el-form-item>

        </el-col>
        <el-col :xs="24" :lg="12" class="mb20">
        <el-form-item ref="Entity_EquipmentId_FormItem" prop="Entity.EquipmentId" :label="$t('message.autotrans._Model_AndonStation_EquipmentId')">
            <el-input v-model="stateAndonStation.vmModel.Entity.EquipmentId" clearable></el-input>
        </el-form-item>

        </el-col>
        <el-col :xs="24" :lg="12" class="mb20">
        <el-form-item ref="Entity_TagId_FormItem" prop="Entity.TagId" :label="$t('message.autotrans._Model_AndonStation_TagId')">
            <el-input v-model="stateAndonStation.vmModel.Entity.TagId" clearable></el-input>
        </el-form-item>

        </el-col>
        <el-col :xs="24" :lg="12" class="mb20">
        <el-form-item ref="Entity_IpAddress_FormItem" prop="Entity.IpAddress" :label="$t('message.autotrans._Model_AndonStation_IpAddress')">
            <el-input v-model="stateAndonStation.vmModel.Entity.IpAddress" clearable></el-input>
        </el-form-item>

        </el-col>
        <el-col :xs="24" :lg="12" class="mb20">
        <el-form-item ref="Entity_TagAddress_FormItem" prop="Entity.TagAddress" :label="$t('message.autotrans._Model_AndonStation_TagAddress')">
            <el-input v-model="stateAndonStation.vmModel.Entity.TagAddress" clearable></el-input>
        </el-form-item>

        </el-col>
        <el-col :xs="24" :lg="12" class="mb20">
        <el-form-item ref="Entity_Remark_FormItem" prop="Entity.Remark" :label="$t('message.autotrans._Model_AndonStation_Remark')">
            <el-input v-model="stateAndonStation.vmModel.Entity.Remark" clearable></el-input>
        </el-form-item>

        </el-col>
      </el-row>

      <WtmTable ref="tableRefAndonStationHeaderStationList1" v-bind="tableDataAndonStationHeaderStationList1" v-model="stateAndonStation.vmModel.Entity.AndonStationHeader_Station"></WtmTable>
      <div style="text-align:right;">
        <WtmButton @click="onSubmitAndonStation"  type="primary" :button-text="$t('message.autotrans.SysSubmit')" style="margin-top:15px;"/>

        <WtmButton @click="onCloseAndonStation"  type="primary" :button-text="$t('message.autotrans.SysClose')" style="margin-top:15px;"/>

      </div>

    </el-form>

  </div>

</el-card>
</div>
</template>


<script setup lang="ts" name="message.autotrans._PageAndonManagementAndonStationEdit;false">
import {  ElMessageBox, ElMessage,ElLoading } from 'element-plus';
import { defineAsyncComponent,reactive, ref, getCurrentInstance, onMounted, nextTick } from 'vue';
import { andonstationApi } from '/@/api/andonmanagement/andonstation';
import other from '/@/utils/other';
import fileApi from '/@/api/file';
import { useRouter } from "vue-router";
const ci = getCurrentInstance() as any;


// 定义变量内容
const tableRefAndonStationHeaderStationList1 = ref();
const tableDataAndonStationHeaderStationList1 = ref({
    // 列表数据（必传）
    data: [],
	// 表头内容（必传，注意格式）
	header: [
      {title:ci.proxy.$t('message.autotrans.Page职位'),key: 'HeaderRole',type: 'textbox',isCheck: true},
      {title:ci.proxy.$t('message.autotrans.Page负责人'),key: 'Header',type: 'textbox',isCheck: true},
      {title:ci.proxy.$t('message.autotrans.Page联系电话'),key: 'ContactNumber',type: 'textbox',isCheck: true},

	],
	// 配置项（必传）
	config: {
        total: 0, // 列表总数
		loading: false, // loading 加载
		isSerialNo: true, // 是否显示表格序号
		isSelection: true, // 是否显示表格多选
		isOperate: true, // 是否显示表格操作栏
        isSub:true,
        isDisabled:false
	}
});

// 定义变量内容
const formRefAndonStation = ref();
const stateAndonStation = reactive({
    vmModel: {
	  Entity:{
        Name: '',
        Code: '',
        DeviceUserId: null,
        EquipmentId: null,
        TagId: null,
        IpAddress: '',
        TagAddress: '',
        Remark: '',
        AndonStationHeader_Station:[],
        ID:null,
      },

	},
    
    AllDeviceUsers: [] as any[],
    AllStations: [] as any[],
});

// 取消
const onCloseAndonStation = () => {
    closeDialog();
};

// 提交
const onSubmitAndonStation = () => {
 	const loadingInstance = ElLoading.service({
		lock: true,
		text: '正在提交中，请等待。。。',
		background: 'rgba(0, 0, 0, 0.7)',
	});
   formRefAndonStation.value?.validate((valid: boolean, fields: any) => {
		if (valid) {
            andonstationApi().edit(stateAndonStation.vmModel).then(() => {
                ElMessage.success(ci.proxy.$t('message._system.common.vm.submittip'));
                emit('refresh');
                closeDialog();
            }).catch((error) => {
                other.setFormError(ci, error);
            }).finally(() => {
			loadingInstance.close();
		    })
		}
        else{
			loadingInstance.close();
        }
	})
};

// 页面加载时
onMounted(() => {
    
    other.getSelectList('/api/AndonManagement/AndonStation/GetFrameworkUsers',[],false).then(x=>{stateAndonStation.AllDeviceUsers = x});
    other.getSelectList('/api/AndonManagement/AndonStationHeader/GetAndonStations',[],false).then(x=>{stateAndonStation.AllStations = x});
    if (ci.attrs["wtmdata"]) {
		stateAndonStation.vmModel.Entity.ID = ci.attrs["wtmdata"].ID;
	}
	else if (useRouter().currentRoute.value.query.id) {
		stateAndonStation.vmModel.Entity.ID = useRouter().currentRoute.value.query.id as any;
	}
	andonstationApi().get(stateAndonStation.vmModel.Entity.ID ?? "").then((data: any) => other.setValue(stateAndonStation.vmModel, data));
});

// 定义子组件向父组件传值/事件
const emit = defineEmits(['refresh','closeDialog']);
// 关闭弹窗
const closeDialog = () => {
    emit('closeDialog');
};
// 暴露变量
defineExpose({

});
</script>

<style scoped lang="scss">

</style>

